#include "parallel.h"

int array_info(double arr[], int n){
    double min = 1.79E308, max = -1.79E308, avg = 0.0, sum = 0.0; 
    #pragma omp parallel for reduction(min:min)
    for(int i = 0; i < n; i++)
        if (arr[i] < min) min = arr[i];
    #pragma omp parallel for reduction(max:max)
    for(int i = 0; i < n; i++)
        if (arr[i] > max) max = arr[i];
    #pragma omp parallel for reduction(+:sum)
    for(int i = 0; i < n; i++) sum += arr[i];
    avg = sum / n; 
    double s = 0.0, s_2 = 0.0; 
    sum = 0.0;
    #pragma omp parallel for reduction(+:sum)
    for(int i = 0; i < n; i++)
        sum += (avg - arr[i]) *  (avg - arr[i]) ;
    s_2 = sum / (n-1);
    s = sqrt(s_2);
    printf("max = %f, min = %f, avg = %f, s = %f\n", max, min, avg, s);
}

int main(int argc, char **argv){
    int n = 200000;
    double arr[n];
    for(int i = 0; i < n ; i++) arr[i] = rand();
    
    for(int i = 0; i < threads_list_num; i++){
        double start, end; 
        int thread = threads[i]; 
        omp_set_num_threads(thread);
        start = omp_get_wtime(); 
        array_info(arr, n);
        end = omp_get_wtime(); 
        printf("thread %d Work took %f seconds\n",thread, end - start);
    }
}
